//
//  JZHSelectListViewController.m
//  极致荟
//
//  Created by hetao on 14-5-9.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHSelectListViewController.h"
#import "JZHAttentionTableViewCell.h"
#import "JZHPersonaldetailsViewController.h"
#import "JZHSelectViewController.h"
#import "OtherUsers.h"
@interface JZHSelectListViewController ()
{
    NSMutableArray *dataarr;
}
@end

@implementation JZHSelectListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (IBAction)pusLiset:(id)sender {
    [self.navigationController pushViewController:[JZHSelectViewController focusType:self.focusType] animated:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self httpLoad];
}
+ (JZHSelectListViewController *)focusType:(JZHFocusType *)focus
{
    JZHSelectListViewController *jz=[[JZHSelectListViewController alloc]init];
    jz.focusType=focus;
    return jz;
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    [titleLabel setTextColor:[UIColor blackColor]];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    titleLabel.text = [self.focusType tyepChinaes:self.focusType.focusType];
    self.navigationItem.titleView= titleLabel;
    self.lable.text=[self.focusType tyepChinaes:self.focusType.focusType];
    UIImage *img=[UIImage imageNamed:[self.focusType tyepChinaes:self.focusType.focusType]];
    if(img)
    {
        [self.image setImage:img];
    }else
    {
        _topview.hidden=YES;
        [_table setCenter:CGPointMake(_table.center.x, _table.center.y-55)];
    }
    
    //设置左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 44)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;

    
}

- (void)leftDrawerButtonPress:(UIButton*)but
{
    [UINavigationController Pop:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


///加载网络数据
- (void)httpLoad
{
    if(!dataarr)
    {
        dataarr=[[NSMutableArray alloc]init];
        //[MMProgressHUD showWithStatus:@"数据加载中..."];
    }else
    {
        [dataarr removeAllObjects];
    }
    
    
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[self.focusType tyepString:self.focusType.focusType],@"attentionType",[self.focusType.selectft objectForKey:@"key"],@"attentionTypeId", nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"attention/attentionMemberList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
            
        {
            [MMProgressHUD dismiss];
            NSLog(@"%@",data);
            NSArray *arr=[[data objectForKey:@"data"] objectForKey:@"list"];
           
            for(NSDictionary *datadic in arr)
            {
                OtherUsers *ouser=[[OtherUsers alloc]init];
                if([datadic objectForKey:@"cityName"]==[NSNull null])
                {
                    ouser.citydic=[[NSDictionary alloc] initWithObjectsAndKeys:@"不详", @"name",nil];
                }else
                {
                    ouser.citydic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"cityName"], @"name",nil];
                }
                
                if([datadic objectForKey:@"job"]==[NSNull null])
                {
                    ouser.jobdic=[[NSDictionary alloc] initWithObjectsAndKeys:@"暂时无法获取", @"name",nil];
                }else
                {
                 ouser.jobdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"job"], @"name",nil];
                }
               
                if([datadic objectForKey:@"profession"]==[NSNull null])
                {
                     ouser.persdic=[[NSDictionary alloc] initWithObjectsAndKeys:@"暂时无法获取", @"name",nil];
                }else
                {
                    ouser.persdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"profession"], @"name",nil];
                }
                
                ouser.name=[datadic objectForKey:@"userName"];
                ouser.userId=[[datadic objectForKey:@"userId"] intValue];
                ouser.userHeadImage=[[[data objectForKey:@"data"] objectForKey:@"imgPrefix"] stringByAppendingString:[datadic objectForKey:@"userAvatar"]];
                [dataarr addObject:ouser];
                
            }
            [self.table reloadData];
        }else
        {
            [MMProgressHUD showInformationWithTips:@"数据加载失败"];
        }
    }];
}
#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
       return dataarr.count;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"adf";
    JZHAttentionTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"JZHAttentionTableViewCell" owner:self options:nil] objectAtIndex:0];
    }
    [cell addACTCellData:dataarr[indexPath.row]];
    cell.but.hidden=YES;
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 71;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self.navigationController pushViewController:[JZHPersonaldetailsViewController shareName:[dataarr objectAtIndex:indexPath.row]] animated:YES];
    
}

@end
